*********************************************************************
* This do file creates a STATA dataset from the original LFS files. *
* The monthly survey files will be combined into yearly STATA       *
* datasets files                                    	            *  
*********************************************************************


*Brochu
* Minimum wage
* LFS

* original program name from Brochu: LFSdata.do
* created: October 10, 2013
* updated: October 10, 2013
* modified: July, 2015
* modified by: Oscar Becerra and Daniel Gao
* modified by Iain on March 4, 2019.


clear
discard
cap log close

/* set directories */
* note:  no spaces allowed in directory names.

* rawdata is the directory that contains the raw data
local rawdata "V:\Townsend_5609\Iain_Feb27\rawdata"

* workdata is the directory that contains the working data sets
local workdata "V:\Townsend_5609\Iain_Feb27\Data"




set more off

set memory 700m
set matsize 600

// Loop over years and months to import the data

forvalues year = 1996/2016 { 
	forvalues month = 1/12 {

		if `year' <= 1999 { 	  	/* An adjustment needs to be made to access    */
			local k= `year'-1900	/* the LFS files.  For example, tab0102.prn    */
			local yr "`k'"          /* is the numbers for january 2002.            */
		}		
		else if `year'>=2000 & `year'<=2009 { 
			local k=`year'-2000	 
			local yr "0`k'"   
		}		
		else {
			local yr=`year'-2000 
		}
		if `month' <= 9 {			
			local mnth "0`month'"
		}		
		else {
			local mnth "`month'"
		}		
		

		clear	
		use `rawdata'\LFS_`year'_Master_`mnth'`yr'_F1.dta,clear
		display "year=`year' month=`month'"

		summarize
		if `month' == 1 {
			compress
			save "`workdata'\LFS`year'.dta", replace 
		}
			
		else {
			compress
			append using "`workdata'\LFS`year'.dta"
    		save "`workdata'\LFS`year'.dta", replace 
		}
	}			
}

